package org.boot.wxipad.common.util.http;

import org.boot.wxipad.common.util.http.apache.ApacheSimpleGetRequestExecutor;

import java.io.IOException;

/**
 * @author liyuncong
 * @version 1.0
 * @file SimpleGetRequestExecutor
 * @brief 简单GET请求执行器
 * @details 简单GET请求执行器
 * @date 2024-08-09
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                     NAME               DESCRIPTION
 * 2024-08-09               liyuncong          Created
 */
public abstract class SimpleGetRequestExecutor<H, P> implements RequestExecutor<String, String> {

    protected RequestHttp<H, P> requestHttp;

    public SimpleGetRequestExecutor(RequestHttp requestHttp) {
        this.requestHttp = requestHttp;
    }

    @Override
    public void execute(String uri, String data, ResponseHandler<String> handler) throws IOException {
        handler.handle(this.execute(uri, data));
    }

    public static RequestExecutor<String, String> create(RequestHttp<?, ?> requestHttp) {
        switch (requestHttp.getRequestType()) {
            case APACHE_HTTP:
                return new ApacheSimpleGetRequestExecutor(requestHttp);
            default:
                throw new IllegalArgumentException("非法请求参数");
        }
    }
}
